const filmModel = require('../model/filmModel.js');


module.exports.find = async function(searchObj,page){
     // 分页查询
     let {current,size} = page;
     // 获取数据总数
     let total = await filmModel.countDocuments(searchObj)
     // 根据总数/每页显示数得到总页数
     let totalPage = Math.ceil(total / size);
     // limit是每页显示数，skip通过(当前页-1) * 每页显示得到
     let rows = await filmModel
                 .find(searchObj)
                 .limit(parseInt(size))
                 .skip((current - 1) * size);
     return {
         current,size,total,totalPage,rows
     }
}
module.exports.findAll = async function(){
    return await filmModel.find();
}
module.exports.findById = async function(id){
    return await filmModel.findById(id);
}